package com.ht.power3d.vmap.persist;

import com.ht.power3d.vmap.*;
import com.ht.power3d.geop.GeoGL;

import java.io.*;

/**
 * @author SU Xinyi
 * @since 2009-6-10
 */
public class SurfacePersist {
    public static void saveSurface(Surface surface, String filePath){
        try {
            FileOutputStream fos = new FileOutputStream(filePath);
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(surface);
            oos.close();
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
    }
    public static Surface loadSurface(String filePath){
        try {
            FileInputStream fis = new FileInputStream(filePath);
            ObjectInputStream ois = new ObjectInputStream(fis);
            Surface rs = (Surface) ois.readObject();
            ois.close();
            return rs;
        } catch (FileNotFoundException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (ClassNotFoundException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        return null;
    }

    public static void saveSurface(Surface surface, File file){
        try {
            FileOutputStream fos = new FileOutputStream(file);
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(surface);
            oos.close();
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
    }
    public static Surface loadSurface(File file){
        try {
            FileInputStream fis = new FileInputStream(file);
            ObjectInputStream ois = new ObjectInputStream(fis);
            Surface rs = (Surface) ois.readObject();
            ois.close();
            return rs;
        } catch (FileNotFoundException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (ClassNotFoundException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        return null;
    }

    public static void main(String[] args) {
        DataPointsLoader dataPointsLoader = new DataPointsLoaderImpl1();
        String filePath = "e:/s1.dat";
        try {
            GeoGL.FRAME_WIDTH_3D = 692.353f;
            GeoGL.FRAME_HEIGHT_3D = 590.035f;            
            Surface s1 = new Surface(100,100,0,0, GeoGL.FRAME_WIDTH_3D,GeoGL.FRAME_HEIGHT_3D,0,0,GeoGL.FRAME_WIDTH_3D,GeoGL.FRAME_HEIGHT_3D,dataPointsLoader.getDataPoints());
            saveSurface(s1, filePath);
            Surface s2 = loadSurface(filePath);
            System.out.println();
        } catch (Exception e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }


    }
}
